package com.example.Controller;

import com.example.Entity.Message;
import com.example.Entity.Product;
import com.example.Entity.ProductVo;
import com.example.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ProductController {

    @Autowired
    private ProductService productService;

    @GetMapping("/api/v1/admin/products")
    public ProductVo findAll() {
        return productService.findAll();
    }

    @PostMapping("/api/v1/admin/products")
    public Message save(@RequestBody Product product) {
        return productService.save(product);
    }

    @GetMapping("/api/v1/admin/products/{id}")
    public Product getById(@PathVariable("id") Integer id) {
        return productService.getById(id);
    }

    @PutMapping("/api/v1/admin/products/{id}")
    public Message updateById(@PathVariable("id") Integer id, @RequestBody Product product) {
        return productService.updateById(id, product);
    }

    @DeleteMapping("/api/v1/admin/products/{id}")
    public Message delById(@PathVariable("id") Integer id) {
        return productService.delById(id);
    }

}
